<?php
$config = fopen("config.ini", "r");
if ($config == false){
    header("Location: configurar.html");
}
else{
    require 'conectarBD.php';
?>
<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Módulo de gestión de contratos.</title>
        <link rel="STYLESHEET" type="text/css" href="estilos/general.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="javascript/funciones.js"></script>
    </head>
    <body>
        <?php
        if(!isset($_POST["username"])){
            ?>
        <form method="POST" class="login">
            <fieldset class="login">
                <legend>Inicar sesión</legend>
                <span class="dlogin">
                    <label for="username">Usuario</label>
                    <input type="text" name="username">
                </span>
                <span class="dlogin">
                    <label for="password">Contraseña</label>
                    <input type="password" name="password">
                </span>
                <input type="submit" value="Iniciar sesión" id="btnSumbit">
            </fieldset>
        </form>
        <?php
        }
        else{
            $user = $_POST["username"];
            $pass = sha1($_POST["password"]);
            $query = "select U_Pass from Usuario where U_Login = '" . $user . "'";
            $res = mysqli_query($con, $query);
            $row = mysqli_fetch_array($res);
            if($row["U_Pass"] == $pass){
                setcookie ("user", $user . "/" . $pass, time() + 60*60*24);
                header("Location: index.php");
            }
            else 
                header("Location: login.php");
        }
        ?>
        <footer>Creado por: Luis Felipe Gonzalez Moreno, 2013.</footer>
    </body>
</html>
<?php
}
?>